#创建JINGDONG登录对象类
from selenium.webdriver.common.action_chains import ActionChains  #鼠标操作类
from selenium.webdriver.common.by import By
from .Page import Page
from time import sleep

class Login(Page):
    '''用户登录界面'''
    #定位器
    JINGDONG_login_user_loc = (By.LINK_TEXT,"您好，请登录")
    JINGDONG_login_button_loc = (By.LINK_TEXT,"账户登录")
    #从主页跳转到登录界面
    def bbs_login(self):
        self.find_element(*self.JINGDONG_login_user_loc).click()
        sleep(2)
        self.find_elemnet(*self.JINGDONG_login_button_loc).click()

    login_username_loc = (By.ID, "loginname")
    login_password_loc = (By.ID, "nloginpwd")
    login_button_loc = (By.ID, "loginsubmit")
    #登录用户名
    def login_username(self,username):
        self.find_elemnet(*self.login_username_loc).send_keys(username)
    #登录密码
    def login_password(self,password):
        self.find_elemnet(*self.login_password_loc).send_keys(password)
    #登录按钮
    def login_button(self):
        self.find_elemnet(*self.login_button_loc).click()

    #定义统一登录入口
    def user_login(self,username ="15216707828",password="15216707828li"):
        self.open()
        self.bbs_login()
        self.login_username(username)
        self.login_password(password)
        self.login_button()

    user_error_hint_loc = (By.XPATH,"//*[@id='mainForm']/div[2]/span[1]")
    pawd_error_hint_loc =(By.XPATH,"//*[@id='mainForm']/div[2]/span[1]")
    user_login_success_loc =(By.ID,"mzCustName")
    #用户名错误提示
    def user_error_hint(self):
        return self.find_elemnet(*self.user_error_hint_loc).text
    #密码提示错误
    def pawd_error_hint(self):
        return self.find_elemnet(*self.pawd_error_hint_loc).text
    #登录成功提示
    def user_login_success(self):
        return self.find_elemnet(*self.user_login_success_loc).text
